//
//  ClockDTDKTableViewCell.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/8/15.
//

#import "ClockDTDKTableViewCell.h"

#import "YTBaseSelectStringView.h"
#import "YTBaseEditorStringView.h"
#import "DigitalInputView.h"
#import "TemplateFoundDetailsDXXZTableViewCell.h"
#import "TemplateFoundDetailsDHTableViewCell.h"

@interface ClockDTDKTableViewCell ()
@property (nonatomic ,strong) UIView * makeview;
@property (nonatomic ,strong) UILabel * nameLab;
@property (nonatomic ,strong) UIButton * sxBtn;
@property (nonatomic ,strong) UIView * AllZview;
@end
@implementation ClockDTDKTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self setupView];
    }
    return self;
}


- (void)setupView{
    
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.whiteColor;
    self.userInteractionEnabled = YES;
    self.contentView.userInteractionEnabled = YES;
    
    UIView * makeview = [UIView new];
    self.makeview = makeview;
    makeview.backgroundColor = UIColor.whiteColor;
    [DTKTool YJBK:kwt(5) andView:makeview andWidth:0.5 andColor:KcolorHex(@"#D9D9D9")];
    [self.contentView addSubview:makeview];
    [makeview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.offset(0);
        make.bottom.offset(kwt(-10));
    }];
    
    UILabel * nameLab = [DTKTool labelWithText:@"-" andFont:kCFont(18) andTextColor:KcolorHex(@"#222222")];
    [makeview addSubview:nameLab];
    self.nameLab = nameLab;
    [makeview addSubview:nameLab];
    [nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(22));
        make.top.offset(kwt(17));
        make.height.offset(kwt(19));
    }];
    
    
    UIButton * sxBtn = [UIButton buttonWithType:0];
    self.sxBtn = sxBtn;
    sxBtn.addTarget(self,@selector(openSXBtnClick));
    [sxBtn setImage:[UIImage imageNamed:@"template_expand"] forState:UIControlStateNormal];
    [sxBtn setImage:[UIImage imageNamed:@"template_retract"] forState:UIControlStateSelected];
    [self addSubview:sxBtn];
    [sxBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(nameLab);
        make.width.height.offset(kwt(20));
        make.right.offset(kwt(-14));
    }];
    
    UIView * AllZview = [UIView new];
    self.AllZview = AllZview;
    AllZview.backgroundColor = UIColor.whiteColor;
    [DTKTool YJ:kwt(5) andView:AllZview];
    [makeview addSubview:AllZview];
    [AllZview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(45));
        make.right.offset(kwt(-10));
        make.left.offset(kwt(10));
        make.bottom.offset(kwt(-10));
    }];
    
}
- (void)openSXBtnClick{
    self.ponmodel.isSQ = !self.ponmodel.isSQ;
    if(self.openReloadBlock){
        self.openReloadBlock();
    }
}

- (void)setPonmodel:(pondModelListModel *)ponmodel{
    _ponmodel = ponmodel;
    self.nameLab.text = ponmodel.name;
    self.sxBtn.selected = ponmodel.isSQ;
    
    [self.AllZview.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    ///任务只要一个
    NSArray <TemplateFoundDetailsTaskItemModelListModel *> * modelArray = ponmodel.taskItemModelList;

    MJWeakSelf
    CGFloat Y = 0;
    for (TemplateFoundDetailsTaskItemModelListModel * item in modelArray) {
        UIView * listview = [UIView new];
        listview.backgroundColor = UIColor.whiteColor;// KcolorHex(@"#F6F7F9");
        [self.AllZview addSubview:listview];
        [DTKTool YJ:kwt(5) andView:listview];
        [listview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.offset(0);
            make.top.offset(Y) ;
            make.height.offset(item.DKCellH);
        }];
        /// 样式;1:多项选择 2:下单单选3:数字输入框4:单行文本 5:多行文本
        if(item.pattern == 1){
            CGFloat dxY = kwt(45);
            if(item.configureItem != 1){///不绘制顶部,统一配置
                CGFloat X = kwt(10);
                UIView * dxview = [UIView new];
                dxview.backgroundColor = KcolorHex(@"#F6F7F9");
                [DTKTool YJ:kwt(5) andView:dxview];
                [listview addSubview:dxview];
                [dxview mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.top.offset(0);
                    make.left.right.offset(0);
                    make.height.offset(item.CellH - kwt(10));
                }];
                
                
                UILabel * lab = [DTKTool labelWithText:@"" andFont:kCFont(17) andTextColor:KcolorHex(@"#222222")];
                lab.attributedText = [DTKTool AttributedStringWithStr:[NSString stringWithFormat: @"%@%@",((item.forceFlag == 1)?@"*":@""),item.name] andNodeColor:KcolorHex(@"#222222") andSeledColor:KcolorHex(@"#FA0F0F") andFont:kCFont(17) andPattenr:@"[*]"];
                [listview addSubview:lab];
                [lab mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.offset(kwt(12));
                    make.top.offset(kwt(16));
                    make.height.offset(kwt(18));
                }];
                UILabel * templab = [DTKTool labelWithText:@" (可多选)" andFont:kFont(17) andTextColor:KcolorHex(@"#7F7F7F")];
                [listview addSubview:templab];
                templab.textAlignment = NSTextAlignmentCenter;
                [templab mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(lab.mas_right);
                    make.centerY.equalTo(lab);
                }];
            
                
                for (TemplateFoundDetailsItemModelListModel * childModel in item.itemModelList) {
                    UIView * btnview = [UIView new];
                    btnview.addClickBlock(^{
                        [weakSelf btnclick:childModel];
                    });
                    [DTKTool YJBK:kwt(6) andView:btnview andWidth:1 andColor:childModel.checkedFlag?KcolorHex(@"#0967FF"):KcolorHex(@"#BFBFBF")];
                    UILabel * lab = [DTKTool labelWithText:childModel.name andFont:kFont(16) andTextColor:childModel.checkedFlag?KcolorHex(@"#0967FF"):KcolorHex(@"#373C45")];
                    [btnview addSubview:lab];
                    lab.textAlignment = NSTextAlignmentCenter;
                    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
                        make.left.offset(kwt(10));
                        make.right.offset(kwt(-10));
                        make.centerY.offset(0);
                    }];
                    if(childModel.checkedFlag){
                        UIImageView * xzimg = kimageView(@"template_selete");
                        [btnview addSubview:xzimg];
                        [xzimg mas_makeConstraints:^(MASConstraintMaker *make) {
                            make.right.bottom.offset(0);
                            make.height.offset(kwt(11));
                            make.width.offset(kwt(10));
                        }];
                    }
                    
                    [dxview addSubview:btnview];
                    if(X + childModel.nameW > kwt(340)){
                        X = kwt(10);
                        dxY += kwt(48);
                    }
                    btnview.frame = CGRectMake(X, dxY, childModel.nameW, kwt(32));
                    X += childModel.nameW + kwt(14);
                }
            } else {
                dxY = -(kwt(45) + kwt(10));///抵消
            }
            CGFloat itemY = dxY + kwt(45) + kwt(10);
            ///筛选是否有选中子选项要绘制
            for (TemplateFoundDetailsItemModelListModel * childModel in item.itemModelList) {///子选项绘制
                if(childModel.checkedFlag == 1){
                    if(childModel.itemList.count > 1){///有副标题的
                        CGFloat fbtdxY = kwt(45);
                        
                        UIView * fbtdxview = [UIView new];
                        fbtdxview.backgroundColor = KcolorHex(@"#F6F7F9");
                        [DTKTool YJ:kwt(5) andView:fbtdxview];
                        [listview addSubview:fbtdxview];
                        [fbtdxview mas_makeConstraints:^(MASConstraintMaker *make) {
                            make.top.offset(itemY);
                            make.left.right.offset(0);
                            make.height.offset(childModel.itemListViewH - kwt(10));
                        }];
                        UILabel * lab = [DTKTool labelWithText:childModel.name andFont:kFont(17) andTextColor:KcolorHex(@"#222222")];
                        [fbtdxview addSubview:lab];
                        [lab mas_makeConstraints:^(MASConstraintMaker *make) {
                            make.left.offset(kwt(10));
                            make.top.offset(kwt(14));
                            make.height.offset(kwt(18));
                        }];
                        for (TemplateFoundDetailsItemListModel * item in childModel.itemList) {
                            /// 样式;1:多项选择 2:下单单选3:数字输入框4:单行文本 5:多行文本
                            if(item.pattern == 1){
                                CGFloat X = kwt(10);
                                CGFloat dxY = kwt(45);
                                UIView * dxview = [UIView new];
                                dxview.backgroundColor = KcolorHex(@"#F6F7F9");
                                [DTKTool YJ:kwt(5) andView:dxview];
                                [fbtdxview addSubview:dxview];
                                [dxview mas_makeConstraints:^(MASConstraintMaker *make) {
                                    make.top.offset(fbtdxY);
                                    make.left.right.offset(0);
                                    make.height.offset(item.viewH - kwt(10));
                                }];
                                
                                
                                UILabel * lab = [DTKTool labelWithText:@"" andFont:kCFont(17) andTextColor:KcolorHex(@"#222222")];
                                lab.attributedText = [DTKTool AttributedStringWithStr:[NSString stringWithFormat: @"%@%@",((item.forceFlag == 1)?@"*":@""),item.name] andNodeColor:KcolorHex(@"#222222") andSeledColor:KcolorHex(@"#FA0F0F") andFont:kCFont(17) andPattenr:@"[*]"];
                                [dxview addSubview:lab];
                                [lab mas_makeConstraints:^(MASConstraintMaker *make) {
                                    make.left.offset(kwt(10));
                                    make.top.offset(kwt(14));
                                    make.height.offset(kwt(18));
                                }];
                                UILabel * templab = [DTKTool labelWithText:@" (可多选)" andFont:kFont(17) andTextColor:KcolorHex(@"#7F7F7F")];
                                [dxview addSubview:templab];
                                templab.textAlignment = NSTextAlignmentCenter;
                                [templab mas_makeConstraints:^(MASConstraintMaker *make) {
                                    make.left.equalTo(lab.mas_right);
                                    make.centerY.equalTo(lab);
                                }];
                                
//                                UILabel * lab = [DTKTool labelWithText:@"-" andFont:kCFont(18) andTextColor:KcolorHex(@"#222222")];
//                                lab.attributedText = [DTKTool AttributedStringWithStr:[NSString stringWithFormat:@"%@(可多选)",item.name] andNodeColor:KcolorHex(@"#222222") andSeledColor:KcolorHex(@"#7F7F7F") andFont:kCFont(18) andPattenr:@"(\\(可多选\\))"];
//                                [dxview addSubview:lab];
//                                [lab mas_makeConstraints:^(MASConstraintMaker *make) {
//                                    make.left.offset(kwt(10));
//                                    make.top.offset(kwt(14));
//                                    make.height.offset(kwt(18));
//                                }];
                                
                                for (TemplateFoundDetailsChildrenModelListModel * childModel in item.childrenModelList) {
                                    
                                    UIView * btnview = [UIView new];
                                    btnview.addClickBlock(^{
                                        [weakSelf btnclick:childModel];
                                    });
                                    [DTKTool YJBK:kwt(6) andView:btnview andWidth:1 andColor:childModel.checkedFlag?KcolorHex(@"#0967FF"):KcolorHex(@"#BFBFBF")];
                                    UILabel * lab = [DTKTool labelWithText:childModel.name andFont:kFont(16) andTextColor:childModel.checkedFlag?KcolorHex(@"#0967FF"):KcolorHex(@"#373C45")];
                                    [btnview addSubview:lab];
                                    lab.textAlignment = NSTextAlignmentCenter;
                                    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
                                        make.left.offset(kwt(10));
                                        make.right.offset(kwt(-10));
                                        make.centerY.offset(0);
                                    }];
                                    if(childModel.checkedFlag){
                                        UIImageView * xzimg = kimageView(@"template_selete");
                                        [btnview addSubview:xzimg];
                                        [xzimg mas_makeConstraints:^(MASConstraintMaker *make) {
                                            make.right.bottom.offset(0);
                                            make.height.offset(kwt(11));
                                            make.width.offset(kwt(10));
                                        }];
                                    }
                                    
                                    [dxview addSubview:btnview];
                                    if(X + childModel.nameW > kwt(340)){
                                        X = kwt(10);
                                        dxY += kwt(48);
                                    }
                                    btnview.frame = CGRectMake(X, dxY, childModel.nameW, kwt(32));
                                    X += childModel.nameW + kwt(10);
                                }
                              
                                fbtdxY+= item.viewH - kwt(10);
                            } else  if(item.pattern == 2){
                                YTBaseSelectStringView * view = [YTBaseSelectStringView NewViewWithNil];
                                view.forceFlag = item.forceFlag;
                                view.name = item.name;
                                view.content = item.seledModel.name;
                                view.block = ^(NSString * _Nonnull content) {
                                    NSMutableArray * nameArray = [NSMutableArray array];
                                    int i = 0;
                                    int selectIndex = 0;
                                    for (TemplateFoundDetailsChildrenModelListModel * itemmodel in item.childrenModelList) {
                                        [nameArray addObject:itemmodel.name];
                                        if([item.seledModel.name isEqualToString: itemmodel.name]){
                                            selectIndex = i;
                                        }
                                        i ++;
                                    }
                                    [BRStringPickerView showPickerWithTitle:[NSString stringWithFormat:@"请选择%@",item.name] dataSourceArr:nameArray selectIndex:selectIndex resultBlock:^(BRResultModel * _Nullable resultModel) {
                                        for (TemplateFoundDetailsChildrenModelListModel * itemmodel in item.childrenModelList) {
                                            if([itemmodel.name isEqualToString:resultModel.value]){
                                                itemmodel.checkedFlag = 1;
                                            } else {
                                                itemmodel.checkedFlag = 0;
                                            }
                                        }
                                        if(weakSelf.openReloadBlock){
                                            weakSelf.openReloadBlock();
                                        }
                                    }];
                                };
                                [fbtdxview addSubview: view];
                                [view mas_makeConstraints:^(MASConstraintMaker *make) {
                                    make.left.right.offset(0);
                                    make.top.offset(fbtdxY);
                                    make.height.offset(item.viewH);
                                }];
                                fbtdxY+=  item.viewH - kwt(10);
                            } else  if(item.pattern == 3){
                                
                                UIView * makeview = [UIView new];
                                makeview.backgroundColor = KcolorHex(@"#F6F7F9");
                                [DTKTool YJ:kwt(5) andView:makeview];
                                [fbtdxview addSubview:makeview];
                                [makeview mas_makeConstraints:^(MASConstraintMaker *make) {
                                    make.top.offset(fbtdxY);
                                    make.left.right.offset(0);
                                    make.height.offset(item.viewH - kwt(10));
                                }];
                                
                                UILabel * name = [DTKTool labelWithText:@"" andFont:kCFont(18) andTextColor:KcolorHex(@"#222222")];
                                [makeview addSubview:name];
                                name.attributedText = [DTKTool AttributedStringWithStr:[NSString stringWithFormat:@"%@%@",(item.forceFlag==1)?@"*":@"",item.name] andNodeColor:KcolorHex(@"#222222") andSeledColor:KcolorHex(@"#FA0F0F") andFont:kCFont(18) andPattenr:@"[*]"];
                                [name mas_makeConstraints:^(MASConstraintMaker *make) {
                                    make.left.offset(kwt(12));
                                    make.centerY.offset(0);
                                    make.width.offset(kwt(145));
                                }];
                                
                                DigitalInputView * inputview = [DigitalInputView DKNewView];
                                inputview.model = item;///有数据不管类型
                                [makeview addSubview:inputview];
                                inputview.openReloadBlock = ^{
                                    if(weakSelf.openReloadBlock){
                                        weakSelf.openReloadBlock();
                                    }
                                };
                                inputview.openHUDBlock = ^(NSString * _Nonnull str) {
                                    if(weakSelf.openHUDBlock){
                                        weakSelf.openHUDBlock(str);
                                    }
                                };
                                [inputview mas_makeConstraints:^(MASConstraintMaker *make) {
                                    make.right.offset(kwt(-12));
                                    make.centerY.offset(0);
                                    make.width.offset(kwt(170));
                                    make.height.offset(kwt(32));
                                }];
                                
                                
                                fbtdxY+=  item.viewH - kwt(10);
                                
                            } else  if(item.pattern == 4){
                                
                                YTBaseEditorStringView * view = [YTBaseEditorStringView NewViewWithUP];
                                view.forceFlag = item.forceFlag;
                                view.name = item.name;
                                view.content = item.content;
                                view.block = ^(NSString * _Nonnull content) {
                                    item.content = content;
                                };
                                
                                [fbtdxview addSubview: view];
                                [view mas_makeConstraints:^(MASConstraintMaker *make) {
                                    make.left.right.offset(0);
                                    make.top.offset(fbtdxY);
                                    make.height.offset(item.viewH);
                                }];
                                fbtdxY+= item.viewH;
                            } else  if(item.pattern == 5){
                                TemplateFoundDetailsDHView * view = [TemplateFoundDetailsDHView NewView];
                                view.model = item;
                                [fbtdxview addSubview: view];
                                [view mas_makeConstraints:^(MASConstraintMaker *make) {
                                    make.left.right.offset(0);
                                    make.top.offset(fbtdxY);
                                    make.height.offset(item.viewH);
                                }];
                                fbtdxY+=  item.viewH - kwt(10);
                            }
                        }
                        itemY += childModel.itemListViewH;
                    } else {
                        for (TemplateFoundDetailsItemListModel * item in childModel.itemList) {
                            /// 样式;1:多项选择 2:下单单选3:数字输入框4:单行文本 5:多行文本
                            if(item.pattern == 1){
                                CGFloat X = kwt(10);
                                CGFloat dxY = kwt(45);
                                UIView * dxview = [UIView new];
                                dxview.backgroundColor = KcolorHex(@"#F6F7F9");
                                [DTKTool YJ:kwt(5) andView:dxview];
                                [listview addSubview:dxview];
                                [dxview mas_makeConstraints:^(MASConstraintMaker *make) {
                                    make.top.offset(itemY);
                                    make.left.right.offset(0);
                                    make.height.offset(item.viewH - kwt(10));
                                }];
                                
                                
                                UILabel * lab = [DTKTool labelWithText:@"" andFont:kCFont(17) andTextColor:KcolorHex(@"#222222")];
                                lab.attributedText = [DTKTool AttributedStringWithStr:[NSString stringWithFormat: @"%@%@",((item.forceFlag == 1)?@"*":@""),item.name] andNodeColor:KcolorHex(@"#222222") andSeledColor:KcolorHex(@"#FA0F0F") andFont:kCFont(17) andPattenr:@"[*]"];
                                [dxview addSubview:lab];
                                [lab mas_makeConstraints:^(MASConstraintMaker *make) {
                                    make.left.offset(kwt(10));
                                    make.top.offset(kwt(14));
                                    make.height.offset(kwt(18));
                                }];
                                UILabel * templab = [DTKTool labelWithText:@" (可多选)" andFont:kFont(17) andTextColor:KcolorHex(@"#7F7F7F")];
                                [dxview addSubview:templab];
                                templab.textAlignment = NSTextAlignmentCenter;
                                [templab mas_makeConstraints:^(MASConstraintMaker *make) {
                                    make.left.equalTo(lab.mas_right);
                                    make.centerY.equalTo(lab);
                                }];
                                
//                                UILabel * lab = [DTKTool labelWithText:@"-" andFont:kCFont(18) andTextColor:KcolorHex(@"#222222")];
//                                lab.attributedText = [DTKTool AttributedStringWithStr:[NSString stringWithFormat:@"%@(可多选)",item.name] andNodeColor:KcolorHex(@"#222222") andSeledColor:KcolorHex(@"#7F7F7F") andFont:kCFont(18) andPattenr:@"(\\(可多选\\))"];
//                                [dxview addSubview:lab];
//                                [lab mas_makeConstraints:^(MASConstraintMaker *make) {
//                                    make.left.offset(kwt(10));
//                                    make.top.offset(kwt(14));
//                                    make.height.offset(kwt(18));
//                                }];
                                
                                for (TemplateFoundDetailsChildrenModelListModel * childModel in item.childrenModelList) {
                                    
                                    UIView * btnview = [UIView new];
                                    btnview.addClickBlock(^{
                                        [weakSelf btnclick:childModel];
                                    });
                                    [DTKTool YJBK:kwt(6) andView:btnview andWidth:1 andColor:childModel.checkedFlag?KcolorHex(@"#0967FF"):KcolorHex(@"#BFBFBF")];
                                    UILabel * lab = [DTKTool labelWithText:childModel.name andFont:kFont(16) andTextColor:childModel.checkedFlag?KcolorHex(@"#0967FF"):KcolorHex(@"#373C45")];
                                    [btnview addSubview:lab];
                                    lab.textAlignment = NSTextAlignmentCenter;
                                    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
                                        make.left.offset(kwt(10));
                                        make.right.offset(kwt(-10));
                                        make.centerY.offset(0);
                                    }];
                                    if(childModel.checkedFlag){
                                        UIImageView * xzimg = kimageView(@"template_selete");
                                        [btnview addSubview:xzimg];
                                        [xzimg mas_makeConstraints:^(MASConstraintMaker *make) {
                                            make.right.bottom.offset(0);
                                            make.height.offset(kwt(11));
                                            make.width.offset(kwt(10));
                                        }];
                                    }
                                    
                                    [dxview addSubview:btnview];
                                    if(X + childModel.nameW > kwt(340)){
                                        X = kwt(10);
                                        dxY += kwt(48);
                                    }
                                    btnview.frame = CGRectMake(X, dxY, childModel.nameW, kwt(32));
                                    X += childModel.nameW + kwt(10);
                                }
                                itemY+= item.viewH;
                            } else  if(item.pattern == 2){
                                YTBaseSelectStringView * view = [YTBaseSelectStringView NewViewWithUP];
                                view.forceFlag = item.forceFlag;
                                view.name = item.name;
                                view.content = item.seledModel.name;
                                view.block = ^(NSString * _Nonnull content) {
                                    NSMutableArray * nameArray = [NSMutableArray array];
                                    int i = 0;
                                    int selectIndex = 0;
                                    for (TemplateFoundDetailsChildrenModelListModel * itemmodel in item.childrenModelList) {
                                        [nameArray addObject:itemmodel.name];
                                        if([item.seledModel.name isEqualToString: itemmodel.name]){
                                            selectIndex = i;
                                        }
                                        i ++;
                                    }
                                    [BRStringPickerView showPickerWithTitle:[NSString stringWithFormat:@"请选择%@",item.name] dataSourceArr:nameArray selectIndex:selectIndex resultBlock:^(BRResultModel * _Nullable resultModel) {
                                        for (TemplateFoundDetailsChildrenModelListModel * itemmodel in item.childrenModelList) {
                                            if([itemmodel.name isEqualToString:resultModel.value]){
                                                itemmodel.checkedFlag = 1;
                                            } else {
                                                itemmodel.checkedFlag = 0;
                                            }
                                        }
                                        if(weakSelf.openReloadBlock){
                                            weakSelf.openReloadBlock();
                                        }
                                    }];
                                };
                                [listview addSubview: view];
                                [view mas_makeConstraints:^(MASConstraintMaker *make) {
                                    make.left.right.offset(0);
                                    make.top.offset(itemY);
                                    make.height.offset(item.viewH);
                                }];
                                itemY+= item.viewH;
                            } else  if(item.pattern == 3){
                                
                                UIView * makeview = [UIView new];
                                makeview.backgroundColor = KcolorHex(@"#F6F7F9");
                                [DTKTool YJ:kwt(5) andView:makeview];
                                [listview addSubview:makeview];
                                [makeview mas_makeConstraints:^(MASConstraintMaker *make) {
                                    make.top.offset(itemY);
                                    make.left.right.offset(0);
                                    make.height.offset(item.viewH - kwt(10));
                                }];
                                
                                UILabel * name = [DTKTool labelWithText:@"" andFont:kCFont(18) andTextColor:KcolorHex(@"#222222")];
                                [makeview addSubview:name];
                                name.attributedText = [DTKTool AttributedStringWithStr:[NSString stringWithFormat:@"%@%@",(item.forceFlag==1)?@"*":@"",item.name] andNodeColor:KcolorHex(@"#222222") andSeledColor:KcolorHex(@"#FA0F0F") andFont:kCFont(18) andPattenr:@"[*]"];
                                [name mas_makeConstraints:^(MASConstraintMaker *make) {
                                    make.left.offset(kwt(12));
                                    make.centerY.offset(0);
                                    make.width.offset(kwt(145));
                                }];
                                
                                DigitalInputView * inputview = [DigitalInputView DKNewView];
                                inputview.model = item;///有数据不管类型
                                [makeview addSubview:inputview];
                                inputview.openReloadBlock = ^{
                                    if(weakSelf.openReloadBlock){
                                        weakSelf.openReloadBlock();
                                    }
                                };
                                inputview.openHUDBlock = ^(NSString * _Nonnull str) {
                                    if(weakSelf.openHUDBlock){
                                        weakSelf.openHUDBlock(str);
                                    }
                                };
                                [inputview mas_makeConstraints:^(MASConstraintMaker *make) {
                                    make.right.offset(kwt(-12));
                                    make.centerY.offset(0);
                                    make.width.offset(kwt(170));
                                    make.height.offset(kwt(32));
                                }];
                                
                                
                                itemY+= item.viewH;
                                
                            } else  if(item.pattern == 4){
                                
                                YTBaseEditorStringView * view = [YTBaseEditorStringView NewViewWithUP];
                                view.forceFlag = item.forceFlag;
                                view.name = item.name;
                                view.content = item.content;
                                view.block = ^(NSString * _Nonnull content) {
                                    item.content = content;
                                };
                                
                                [listview addSubview: view];
                                [view mas_makeConstraints:^(MASConstraintMaker *make) {
                                    make.left.right.offset(0);
                                    make.top.offset(itemY);
                                    make.height.offset(item.viewH);
                                }];
                                itemY+= item.viewH;
                            } else  if(item.pattern == 5){
                                TemplateFoundDetailsDHView * view = [TemplateFoundDetailsDHView NewView];
                                view.model = item;
                                [listview addSubview: view];
                                [view mas_makeConstraints:^(MASConstraintMaker *make) {
                                    make.left.right.offset(0);
                                    make.top.offset(itemY);
                                    make.height.offset(item.viewH);
                                }];
                                itemY+= item.viewH;
                            }
                        }
                    }
                }
            }
            Y += item.DKDXXZViewH;
        } else if(item.pattern == 2){
            YTBaseSelectStringView * view = [YTBaseSelectStringView NewViewWithUP];
            view.forceFlag = item.forceFlag;
            view.name = item.name;
            view.content = item.itemSeledModel.name;
            view.block = ^(NSString * _Nonnull content) {
                NSMutableArray * nameArray = [NSMutableArray array];
                int i = 0;
                int selectIndex = 0;
                for (TemplateFoundDetailsChildrenModelListModel * itemmodel in item.itemModelList) {
                    [nameArray addObject:itemmodel.name];
                    if([item.itemSeledModel.name isEqualToString: itemmodel.name]){
                        selectIndex = i;
                    }
                    i ++;
                }
                [BRStringPickerView showPickerWithTitle:[NSString stringWithFormat:@"请选择%@",item.name] dataSourceArr:nameArray selectIndex:selectIndex resultBlock:^(BRResultModel * _Nullable resultModel) {
                    for (TemplateFoundDetailsChildrenModelListModel * itemmodel in item.itemModelList) {
                        if([itemmodel.name isEqualToString:resultModel.value]){
                            itemmodel.checkedFlag = 1;
                        } else {
                            itemmodel.checkedFlag = 0;
                        }
                    }
                    if(weakSelf.openReloadBlock){
                        weakSelf.openReloadBlock();
                    }
                }];
            };
            [listview addSubview: view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.offset(0);
                make.top.offset(0);
                make.height.offset(item.DKDXXZViewH);
            }];
            Y += item.DKDXXZViewH ;
            
        } else if(item.pattern == 3){
            
            UIView * makeview = [UIView new];
            makeview.backgroundColor = KcolorHex(@"#F6F7F9");
            [DTKTool YJ:kwt(5) andView:makeview];
            [listview addSubview:makeview];
            [makeview mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.offset(0);
                make.left.right.offset(0);
                make.height.offset(item.DKDXXZViewH - kwt(10));
            }];
            
            UILabel * name = [DTKTool labelWithText:@"" andFont:kCFont(18) andTextColor:KcolorHex(@"#222222")];
            [makeview addSubview:name];
            name.attributedText = [DTKTool AttributedStringWithStr:[NSString stringWithFormat:@"%@%@",(item.forceFlag==1)?@"*":@"",item.name] andNodeColor:KcolorHex(@"#222222") andSeledColor:KcolorHex(@"#FA0F0F") andFont:kCFont(18) andPattenr:@"[*]"];
            //                        self.name = name;
            [name mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.offset(kwt(12));
                make.centerY.offset(0);
                make.width.offset(kwt(145));
            }];
            
            DigitalInputView * inputview = [DigitalInputView DKNewView];
            inputview.model = item;///有数据不管类型
            [makeview addSubview:inputview];
            inputview.openReloadBlock = ^{
                if(weakSelf.openReloadBlock){
                    weakSelf.openReloadBlock();
                }
            };
            inputview.openHUDBlock = ^(NSString * _Nonnull str) {
                if(weakSelf.openHUDBlock){
                    weakSelf.openHUDBlock(str);
                }
            };
            [inputview mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.offset(kwt(-12));
                make.centerY.offset(0);
                make.width.offset(kwt(170));
                make.height.offset(kwt(32));
            }];
            
            
            Y += item.DKDXXZViewH;
            
        } else  if(item.pattern == 4){
            YTBaseEditorStringView * view = [YTBaseEditorStringView NewViewWithUP];
            view.forceFlag = item.forceFlag;
            view.name = item.name;
            view.content = item.content;
            view.block = ^(NSString * _Nonnull content) {
                item.content = content;
            };
            
            [listview addSubview: view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.offset(0);
                make.top.offset(0);
                make.height.offset(item.DKDXXZViewH);
            }];
            Y+= item.DKDXXZViewH;
        } else  if(item.pattern == 5){
            TemplateFoundDetailsDHView * view = [TemplateFoundDetailsDHView NewView];
            view.model = item;
            [listview addSubview: view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.offset(0);
                make.top.offset(0);
                make.height.offset(item.DKDXXZViewH);
            }];
            Y += item.DKDXXZViewH;
        }
    }
    
    
    
}

- (void)btnclick:(TemplateFoundDetailsItemModelListModel *)model{
    //    if(self.model.pattern == 1){//是单选
    //        for (TemplateFoundDetailsItemModelListModel * childModel in self.model.itemModelList) {//子选项
    //            if(childModel == model){
    //                model.checkedFlag = (model.checkedFlag == 1)?0:1;
    //            } else {
    //                childModel.checkedFlag = 0;
    //            }
    //        }
    //    } else {
    model.checkedFlag = (model.checkedFlag == 1)?0:1;
    //    }
    
    if(self.openReloadBlock){
        self.openReloadBlock();
    }
}
@end
